use super::Authenticator;
use async_trait::async_trait;
use std::net::SocketAddr;

pub struct PasswordAuthenticator {
    password: String,
}

impl PasswordAuthenticator {
    pub fn new(password: String) -> Self {
        Self { password }
    }
}

#[async_trait]
impl Authenticator for PasswordAuthenticator {
    async fn authenticate(
        &self,
        _addr: SocketAddr,
        auth: &str,
        _tx: u64,
    ) -> anyhow::Result<(bool, String)> {
        if auth == self.password {
            Ok((true, "user".to_string()))
        } else {
            Ok((false, String::new()))
        }
    }
}
